package com.ayuku.commons.ui.usergroup;

import java.util.logging.Logger;

import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

import com.ayuku.commons.Util;

/**
 * 
 * @author putu kusuma <putukn@gmail.com>
 * 
 */
public class CompUserGroup extends org.eclipse.swt.widgets.Composite {
	protected Text fGroupDesc;
	protected Text fGroupID;
	private GridColumn clmDesc;
	private GridColumn clmId;
	private GridColumn clmDelete;
	private GridColumn clmAdd;
	private GridColumn clmEdit;
	private GridColumn clmView;
	protected Grid tblAuthority;
	private static Logger LOG = Logger.getLogger(CompUserGroup.class.getName());

	public CompUserGroup(final org.eclipse.swt.widgets.Composite parent,
			final int style) {
		super(parent, style);
		initGUI();
	}

	private void initGUI() {
		try {
			this.setBackground(SWTResourceManager.getColor(215, 213, 253));
			setLayout(new GridLayout(2, false));

			final Label label1 = new Label(this, SWT.NONE);
			label1.setText("Kode:");
			label1.setAlignment(SWT.RIGHT);

			label1.setBackground(SWTResourceManager.getColor(215, 213, 253));

			fGroupID = new Text(this, SWT.BORDER);
			GridData gd_fGroupID = new GridData(SWT.LEFT, SWT.CENTER, true,
					false, 1, 1);
			gd_fGroupID.widthHint = 252;
			fGroupID.setLayoutData(gd_fGroupID);

			fGroupID.setTextLimit(20);

			final Label label2 = new Label(this, SWT.NONE);
			label2.setText("Nama:");
			label2.setAlignment(SWT.RIGHT);

			label2.setBackground(SWTResourceManager.getColor(215, 213, 253));

			fGroupDesc = new Text(this, SWT.BORDER);
			fGroupDesc.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
					false, 1, 1));

			fGroupDesc.setTextLimit(50);

			tblAuthority = new Grid(this, SWT.BORDER | SWT.V_SCROLL
					| SWT.H_SCROLL);
			tblAuthority.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
					true, 2, 1));
			tblAuthority.setHeaderVisible(true);

			clmId = new GridColumn(tblAuthority, SWT.NONE);
			clmId.setText("Menu ID");
			clmId.setWidth(1);
			clmId.setResizeable(false);

			clmDesc = new GridColumn(tblAuthority, SWT.NONE);
			clmDesc.setText("Menu Desc");
			clmDesc.setTree(true);
			clmDesc.setWidth(229);

			clmView = new GridColumn(tblAuthority, SWT.CHECK | SWT.CENTER);
			clmView.setText("View");
			clmView.setWidth(50);

			clmAdd = new GridColumn(tblAuthority, SWT.CHECK | SWT.CENTER);
			clmAdd.setText("Add");
			clmAdd.setWidth(50);

			clmEdit = new GridColumn(tblAuthority, SWT.CHECK | SWT.CENTER);
			clmEdit.setText("Edit");
			clmEdit.setWidth(50);

			clmDelete = new GridColumn(tblAuthority, SWT.CHECK | SWT.CENTER);
			clmDelete.setText("Del");
			clmDelete.setWidth(50);

			tblAuthority.setHeaderVisible(true);
			tblAuthority.setFont(SWTResourceManager.getFont("Segoe UI", 8, 0,
					false, false));
			tblAuthority.setLinesVisible(true);

			tblAuthority.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent evt) {
					tblAuthorityWidgetSelected(evt);
				}
			});

			// setList();
			this.layout();

		} catch (Exception e) {
			e.printStackTrace();
			LOG.info(e.getMessage());
			Util.showMsgBox("Gagal load: " + e.getMessage(), 1, getShell());
		}
	}

	private void tblAuthorityWidgetSelected(SelectionEvent evt) {
		System.out.println("tblAuthority.widgetSelected, event=" + evt);
		// TODO add your code for tblAuthority.widgetSelected
	}

}
